#include "Globals.h"

  extern char dirc[512]          = { 0 };
  extern char txtf[512]          = { 0 };
  extern char romf[512]          = { 0 };
  extern char tblf[512]          = { 0 };
  extern char cur_dir[MAXPATH]   = { 0 };
  extern bool inTextShow         = false;

//  extern BYTE *rom      = NULL;
  extern BYTE *ram               = NULL;
  extern TROM rom                = { 0 };
  extern TREG reg                = { 0 };
  extern TVMS vms                = { 0 };
  extern TTBL tbl                = { 0 };

  extern char *moves[8]          = {
    "UP"  , "UP/RT",
    "RT"  , "DN/RT",
    "DN"  , "DN/LT",
    "LT"  , "UP/LT"
  };

//-------------------------//
//                         //
//-------------------------//
LONG GetIndex( char *strg )
{
  char string[256] = { 0 };

//  memset( string, 0, 256 );
  strcpy( string, strg );

  switch( string[0] ) {
    case '$' : return strtoul( &string[1], NULL, 16);
    case '\'': return string[1];
    case '0' :
      switch( string[1] ){
        case 'x':
        case 'X': return strtoul( &string[2], NULL, 16);
        default : return strtoul( string, NULL, 10);
      }
     //-----------
    case 'x' :
    case 'X' : return strtoul( &string[1], NULL, 16);
    case '\\':
      switch( string[1] ){
        case 'x':
        case 'X': return strtoul( &string[2], NULL, 16);
        default : return strtoul( string, NULL, 10);
      }
    default  : return strtoul( string, NULL, 10);
  }
}


//-------------------------//
//                         //
//-------------------------//
void Dec2Bin( BYTE *string, LONG valu, BYTE size )
{
  char binary[256];
  int c;

  memset( binary, 0, 256 );
  //
  for ( c = 0; c < size; c++ ){
    binary[size - (c+1)] = (valu & 0x01);
    valu >>= 1;
  }
  //
  memcpy( string, binary, size );
}


//-----------------------------//
// Load the program data Bank  //
//-----------------------------//
long Snes2Pc( long ofs )
{
  LONG val;

  if ( !ofs ) return 0;

  return ( (ofs | 0xC00000) - 0xC00000 );

}// END OF SUB


//-----------------------------//
// Get the length of the file  //
//-----------------------------//
long FileSize( FILE *tf )
{
  LONG val,
	   	 offset;

  // Test file
  if ( !tf )  return -1;

  // Get size
  offset = ftell( tf );
  fseek( tf, 0, SEEK_END );
  val = ftell( tf );
  fseek( tf, offset, SEEK_SET );

  return val;
}// END OF SUB


